<template>
  <el-image-viewer teleported preview-teleported v-if="images.length>0" @close="close" :url-list="images"/>
</template>
<script lang="ts">
import {defineComponent, ref} from "vue"

export default defineComponent({
  name: "PreviewImage",
  setup(props, {expose}) {
    const images = ref([])

    /**
     * 图片预览
     * @param list
     */
    function viewer(list: string | string[]) {
      images.value = typeof list === 'string' ? [list] : list
    }

    /**
     * 关闭预览
     */
    function close() {
      images.value = []
    }

    expose({close, viewer})
    return {
      images, close
    }
  }
})
</script>